package com.example.ah_geen_pda.ui.datacheck

import android.os.Bundle
import com.example.ah_geen_pda.R
import com.example.ah_geen_pda.BR
import com.example.ah_geen_pda.base.BaseActivity
import com.example.ah_geen_pda.databinding.ActivityDatacheckBinding
import com.example.ah_geen_pda.entity.ToastMessageBean
import kotlinx.android.synthetic.main.activity_datacheck.*
import kotlinx.android.synthetic.main.activity_title.*

class DataCheckActivity : BaseActivity<DataCheckViewModel, ActivityDatacheckBinding>(){
    override fun layoutId(): Int {
        return R.layout.activity_datacheck
    }

    override fun initVariableId(): Int {
        return BR.dataCheckViewModel
    }

    override fun initView(savedInstanceState: Bundle?) {
        tvTitle.text = "资料核对"
        btCheckData.setOnClickListener {
            tvLotID.text = ""
            tvPartName.text = ""
            tvDurableid.text = ""
            tvPARTNAME.text = ""
            tvStepdesc.text = ""
            tvMAINQTY.text = ""
            tvProcedureName.text = ""
            tvState.text = ""
            ivRecipeName.setBackgroundResource(0)

            if (etLot.text.toString() == ""){
                viewModel.defUI.toastEvent.value = ToastMessageBean("请先扫描批号",false)
                return@setOnClickListener
            }
            viewModel.getLotInfo(etLot.text.toString(),false)
        }

    }

    override fun initData() {

        initEdit(etDurable,object : EditTextListener{
            override fun onTextChangeListener(s: String) {
                viewModel.dataItems.forEach {
                    tvLotID.text = ""
                    tvPartName.text = ""
                    tvDurableid.text = ""
                    tvPARTNAME.text = ""
                    tvStepdesc.text = ""
                    tvMAINQTY.text = ""
                    tvProcedureName.text = ""
                    tvState.text = ""
                    ivRecipeName.setBackgroundResource(0)
                    if (it.LOT.DURABLEID == s){
                        viewModel.defUI.toastEvent.value = ToastMessageBean("当前载具已添加",false)
                        return
                    }
                }
                viewModel.getLotInfo(s,true)
            }

        })

        viewModel.defUI.callObserve.observe(this){
            mBinding.setVariable(BR.dataCheckViewModel,viewModel)
        }
    }
}